@extends('default.layouts.adminPublic')
@section('title', '修改资讯')

@section('content')
        <!--导航开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin')}}">首页</a> &raquo; 资讯管理
</div>
<!--导航结束-->
<!--列表开始-->

<div class="result_wrap">
    <div class="result_title">
        <h3>资讯列表</h3>
        @include('flash::message')
    </div>
    <!--快捷导航 开始-->
    <div class="result_content">
        <div class="short_wrap">
            <a href="{{ url('admin/news/') }}"><i class="fa fa-mail-reply"></i>资讯管理</a>
            <a href="{{ url('admin/news/create') }}"><i class="fa fa-plus"></i>添加资讯</a>
        </div>
    </div>
    <!--快捷导航 结束-->
</div>
@foreach($newsInfo as $v)
    <form action="{{ url('/admin/news/update') }}" method="post" name="newsForm" id="newsForm"  onsubmit="return checkForm('#newsForm')">
        <div class="result_wrap border_buttom">
            <input type="hidden" name="_method" value="put">
            {{csrf_field()}}
            <ul class="list_tab make">
                <li class="create-li">
                    <span class="left">文章标题：</span>
                    <span class="right"><input type="text" name="title" value="{{ $v->title }}"></span>
                    <span class="news-err"><em>*{{ $errors->first('title') }}</em><i></i></span>
                </li>
                <li class="create-li">
                    <span class="left">来源：</span>
                    <span class="right"><input type="text" name="source" value="{{ $v->source }}"></span>
                    <span class="news-err"><em>{{ $errors->first('source') }}</em><i>Exp：众联科技</i></span>
                </li>
                <li class="create-li">
                    <span class="left">作者：</span>
                    <span class="right"><input type="text" name="publisher" value="{{ $v->publisher }}"></span>
                    <span class="news-err"><em>{{ $errors->first('publisher') }}</em><i>默认管理员</i></span>
                </li>
                <li class="create-li">
                    <span class="left">所属类别：</span>
                    <span class="right">
                        <select name="firstClass" id="firstClass">
                            <option value="">--请选择--</option>
                            @foreach($firstClass as $firstClassValue)
                                <option value="{{ $firstClassValue->id }}">{{ $firstClassValue->defectsname }}</option>
                            @endforeach
                        </select>
                        <select name="category" id="category">
                            <option  value="">--请选择父类--</option>
                        </select>
                    </span>
                    <span class="news-err"><em>{{ $errors->first('category') }}</em><i>选择资讯文章对应的类别</i></span>
                </li>
                <li class="create-li">
                    <span class="left">标题颜色风格：</span>
                    <span class="right">
                        <select name="style">
                            @foreach($color as $k => $color_value)
                                @if($v->style ==  $k )
                                    <option value="{{ $k }}" selected>{{ $color_value }}</option>
                                @else
                                    <option value="{{ $k }}">{{ $color_value }}</option>
                                @endif
                            @endforeach
                        </select>
                        </span>
                    <span class="news-err"><em>{{ $errors->first('style') }}</em><i>设置资讯文章标题的颜色</i></span>
                </li>
                <li class="create-li border_buttom">
                    <span class="left">设置推荐：</span>
                    <span class="right">
                        @if($v->recommend ==1)
                            <label for="recommend">推荐</label><input type="radio" id="recommend" name="recommend" value="1" checked>
                        @else
                            <label for="recommend">推荐</label><input type="radio" id="recommend" name="recommend" value="1">
                        @endif
                        @if($v->recommend ==0)
                            <label for="noRecommend">取消推荐</label><input type="radio" id="noRecommend" name="recommend" value="0" checked>
                        @else
                            <label for="noRecommend">取消推荐</label><input type="radio" id="noRecommend" name="recommend" value="0" >
                        @endif

                    </span>
                    <span class="news-err"><em>{{ $errors->first('recommend') }}</em><i>设置资讯文章是否为推荐</i></span>
                </li>
            </ul>

            <div class="bbs">
                <script id="editor" type="text/plain"
                        style="width:100%;min-height:250px;line-height:20px;">{!! $v->editorValue !!}</script>
            </div>

            <div class="bbs">
                <script id="editor" type="text/plain" style="width:100%;min-height:250px;line-height:20px;"></script>
            </div>

            <div class="news-submit">
                <div class="submit-left">
                    <input type="hidden" name="id" value="{{ $v->id }}">
                    <input type="hidden" name="img_tag" value="{{ $strRandom or '' }}">
                </div>
                <div class="submit-right"><input type="button" value="提 交" onclick="document.getElementById('newsForm').submit()"><input type="button" class="back" onclick="history.go(-1)" value="返回"></div>
            </div>
        </div>
    </form>
@endforeach
<script>
    var UPLOADER_URL='{{url('/')}}/';
    var uplod_url = "admin/news/upload?img_tag={{ $strRandom }}";
</script>
<script type="text/javascript" charset="utf-8" src="{{asset('/vendor/ueditor/ueditor.config.js')}}"></script>
<script type="text/javascript" charset="utf-8" src="{{asset('/vendor/ueditor/ueditor.all.min.js')}}"> </script>
<script type="text/javascript" charset="utf-8" src="{{asset('/vendor/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
<script type="text/javascript">
    var ue = UE.getEditor('editor', {textarea: 'editorValue'});
    ue.ready(function() {
        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
        //select 目前只做了2级类
        var jsonObj = {!! $Class !!};
        $("#firstClass").change(function(){
            selectOpt($("#firstClass").val());
        });
        //获取分类
        function selectOpt(cateVal){
            firstClass =cateVal;
            var selectHtml = '';
            for(var item in jsonObj[firstClass]){
                selectHtml += "<option value='"+item+"'>"+jsonObj[firstClass][item]+"</option>";
            }
            $("#category").html(selectHtml);
        }
        @foreach($newsInfo as $v)
            selectOpt('{{$v->firstClass}}');
            $("#firstClass").val('{{$v->firstClass}}');
            $("#category").val('{{$v->secondClass}}');
        @endforeach
    });
</script>
@endsection